//
//  FirstView.m
//  ScreenRotateVC
//
//  Created by Liusr on 2017/6/6.
//  Copyright © 2017年 liu. All rights reserved.
//

#import "FirstView.h"
#import "Masonry.h"
@interface FirstView ()
@property (nonatomic, strong) UILabel *l;
@end
@implementation FirstView
-(instancetype)init{
    if (self = [super init]) {
        self.backgroundColor = [UIColor orangeColor];
        _l = [[UILabel alloc]init];
        _l.text = @"这是View上的一个控件";
        [self addSubview:_l];
        [self addConstraints];
        [self addRotatingObserving];
    }
    return self;
}

-(void)addConstraints{
    [self.l mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
    }];
}

#pragma mark- 屏幕旋转
-(void)addRotatingObserving{
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
    //    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}


-(void)deviceOrientationChange:(NSNotification *)notification{
    
    UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
    UIInterfaceOrientation interfaceOrientation = (UIInterfaceOrientation)orientation;
    
    switch (orientation) {
        case UIDeviceOrientationPortraitUpsideDown:
            NSLog(@"UIDeviceOrientationPortraitUpsideDown");
            
            break;
        case UIDeviceOrientationPortrait:
            NSLog(@"UIDeviceOrientationPortrait");
            
            break;
        case UIDeviceOrientationLandscapeLeft:
            NSLog(@"UIDeviceOrientationLandscapeLeft");
            
            break;
        case UIDeviceOrientationLandscapeRight:
            NSLog(@"UIDeviceOrientationLandscapeRight");
            
            break;
            
        default:
            break;
    }
    
    switch (interfaceOrientation) {
            
        case UIInterfaceOrientationPortraitUpsideDown:{
            
            NSLog(@"UIInterfaceOrientationPortraitUpsideDown");
            
        }
            break;
            
        case UIInterfaceOrientationPortrait:{
            
            NSLog(@"UIInterfaceOrientationPortrait");
        }
            
            break;
            
        case UIInterfaceOrientationLandscapeLeft:{
            
            NSLog(@"UIInterfaceOrientationLandscapeLeft");
        }
            
            break;
        case UIInterfaceOrientationLandscapeRight:{
            
            NSLog(@"UIInterfaceOrientationLandscapeRight");
        }
            
            break;
            
        default:
            break;
    }
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
